package view;

import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.AdminQuery;
import controller.Engine;

@SuppressWarnings("serial")
public class AdminView extends JFrame implements Observer{

	JFrame admin = new JFrame("ADMIN");
	static String[] sectors = {
		"Ricerca e Sviluppo",
		"Produzione e Qualità",
		"Logistica",
		"Marketing",
		"Vendite",
		"Amministrazione e Finanza",
		"Personale e Organizzazione",
		"Sistemi Informativi",
		"Relazioni Esterne"
	};
	String[] evn = {
			"Altro",
			"Relazione",
			"Incontro",
			"Team building",
			"Riunione",
			"Modellazione",
			"Progettazione",
			"Testing",
			"Anteprima",
			"Presentazione",
			"Inventario",
			"Ispezione qualità",
			"Controllo rendimento",
			"Acquisto materiali",
			"Distribuzione prodotto",
			"Programmazione produzione",
			"Posizionamento prodotto",
			"Presentazione",
			"Viaggio di lavoro",
			"Fiera",
			"Promozione",
			"Budgeting",
			"Auditing",
			"Consulenza",
			"Presentazione bilancio",
			"Resoconto parziale",
			"Selezione",
			"Formazione",
			"Carrier day",
			"Controllo",
			"Consulenza",
			"Sponsor",
			"Congresso",
			"Conferenza",
			"Workshop",
			"Media travel",
			"Beneficenza",
			"Cerimonia",
			"Premiazione",
			"Giornalismo",
			"Concerto",
			"Festa"
	};
	public AdminView(String view){
		new AdminQuery();
		admin = this;
		admin.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e)
			{
				admin.dispose();
				Engine.restartHome("");
			}
		});
		if (AdminQuery.obs.countObservers()!=0)
			AdminQuery.obs.deleteObservers();
		AdminQuery.obs.addObserver(this);
		startAdminView(view);
	}

	public void startAdminView(String view){
		JPanel div = new JPanel();
		switch (view){
		case "utnSt":{
			Vector<JPanel> lvl = new Vector<JPanel>();
			JPanel cont = new JPanel();
			div.setLayout(new BoxLayout(div,BoxLayout.Y_AXIS));
			div.add(new JLabel("Statistiche utenti iscritti:"));
			for (int i=0;i<sectors.length;i++){
				lvl.add(new JPanel());
				lvl.get(i).add(new JLabel("["+AdminQuery.obs.getCountUtnOfSector(i)+"] "+sectors[i]+" "));
				cont.add(lvl.get(i));
			}
			lvl.add(new JPanel());
			lvl.get(lvl.size()-1).add(new JLabel("["+AdminQuery.obs.getCountUtnOfSector(512)+"] Admin "));
			cont.add(lvl.get(lvl.size()-1));
			lvl.add(new JPanel());
			lvl.get(lvl.size()-1).add(new JLabel("["+AdminQuery.obs.getCountUtnOfSector(600)+"] Totale utenti "));
			cont.add(lvl.get(lvl.size()-1));
			for (int i=0;i<lvl.size();i++)
				lvl.get(i).setLayout(new GridLayout(1,1));
			cont.setLayout(new GridLayout(lvl.size()+1,1));
			div.add(cont);
			break;
		}
		case "evnSt":{
			Vector<JPanel> lvl = new Vector<JPanel>();
			JPanel cont = new JPanel();
			div.setLayout(new BoxLayout(div,BoxLayout.Y_AXIS));
			div.add(new JLabel("Statistiche eventi programmati:"));
			for (int i=0;i<evn.length;i++){
				lvl.add(new JPanel());
				lvl.get(i).add(new JLabel("["+AdminQuery.obs.getCountEvnOfType(evn[i])+"] "+evn[i]+" "));
				cont.add(lvl.get(i));
			}
			lvl.add(new JPanel());
			lvl.get(lvl.size()-1).add(new JLabel("["+AdminQuery.obs.getCountEvnOfType("512")+"] Totale eventi "));
			cont.add(lvl.get(lvl.size()-1));
			for (int i=0;i<lvl.size();i++)
				lvl.get(i).setLayout(new GridLayout(1,2));
			cont.setLayout(new GridLayout(lvl.size()/2,2));
			div.add(cont);
			break;
		}
		}
		admin.setIconImage(Engine.immaginelog);
		admin.setTitle("Admin: Statistiche");
		admin.add(div);
		//admin.setPreferredSize(new Dimension(50,50));
		admin.setVisible(true);
		admin.pack();
	}

	@Override
	public void update(Observable o, Object arg) {

	}

}
